常用語言[C++/C#/JAVA/PHP] switch語法範例 收藏
常用語言[C++/C#/JAVA/PHP] switch語法範例 收藏
C++ https://msdn.microsoft.com/zh-tw/library/k0t5wee3.aspx
// switch_statement1.cpp #include <stdio.h> int main() { char *buffer = “Any character stream”; int capa, lettera, nota; char c; capa = lettera = nota = 0; while ( c = *buffer++ ) // Walks buffer until NULL { switch ( c ) { case ‘A’: capa++; break; case ‘a’: lettera++; break; default: nota++; } } printf_s( “\nUppercase a: %d\nLowercase a: %d\nTotal: %d\n”, capa, lettera, (capa + lettera + nota) ); } |
C# https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/keywords/switch
using System; public class Example |
JAVA http://www.codedata.com.tw/book/java-basic-source/ch6-3.htm
public class SwitchDemo{ |
PHP http://php.net/manual/en/control-structures.switch.php
<?php switch ($i) { case 0: echo “i equals 0”; break; case 1: echo “i equals 1”; break; case 2: echo “i equals 2”; break; default: echo “i is not equal to 0, 1 or 2”; } ?> |