FreeBASIC マニュアルのトップに戻る

FreeBASIC DevSelectCase

目次→FreeBASIC のハッキング→FreeBASIC でのハッキングのための情報Select Case←オリジナル・サイト

Select Case



基本的な実装

dim i as integer		dim i as integer

				scope
select case i + 123			dim temp as integer = any
					temp = i + 123

case 1					if( temp <> 1 ) then goto cmplabel1
					scope
	print "1"				print "1"
					end scope
					goto endlabel

case 2					cmplabel1:
					if( temp <> 2 ) then goto cmplabel2
					scope
	print "2"				print "2"
					end scope
					goto endlabel

case else				cmplabel2:
					scope
	print "else"				print "else"
					end scope

end select				cmplabel3:    '' unused only because in this example the last CASE is not conditional
					endlabel:
				end scope



strings/zstrings/fixstrs での SELECT CASE

dim s as string			dim s as string

				scope
select case s + "1"			dim temp as string

					fb_StrAssign( temp, s )
					fb_StrConcatAssign( temp, "1" )

case "1"				if( fb_StrCompare( temp, "1" ) <> 0 ) then goto cmplabel1
					scope
	print "1"				print "1"
					end scope
					goto endlabel

					cmplabel1:
end select				endlabel:
					fb_StrDelete( temp )    '' destroying the temp var at scope end
				end scope

				fb_StrDelete( s )


wstrings での SELECT CASE

dim w as wstring * 10			dim w as wstring * 10

					scope
select case w + wstr( "1" )			dim temp as wstring ptr

						dim tempexpr as wstring ptr = w + wstr( "1" )
						temp = fb_WstrAlloc( fb_WstrLen( tempexpr ) )
						fb_WstrAssign( temp, tempexpr )

case wstr( "1" )				if( fb_WstrCompare( temp, wstr( "1" ) ) <> 0 ) then goto cmplabel1
						scope
	print "1"					print "1"
						end scope
						goto endlabel

						cmplabel1:
end select					endlabel:
						fb_WstrDelete( temp )    '' destroying the temp var at scope end
					end scope



一時変数無しの SELECT CASE

select ステートメントに与えられた式が、単に単純変数アクセスなら、一時変数を作る必要はありません。
この場合、与えられた変数は、それ自身、各 case ステートメントで比較の中で使われます。
例えば:

dim i as integer		dim i as integer

				scope
select case i

case 1					if( i <> 1 ) then goto cmplabel1
					scope
	print "1"				print "1"
					end scope
					goto endlabel

end select				cmplabel1:
					endlabel:
				end scope

FreeBASIC の開発者用情報 に戻る
目次に戻る
ページ歴史:2016-03-12 13:41:51
日本語翻訳:WATANABE Makoto、原文著作者:DkLwikki

ホームページのトップに戻る

表示-非営利-継承