Skip to content

Instantly share code, notes, and snippets.

@daleth90
Last active Nov 10, 2018
Embed
What would you like to do?
using System;
namespace Playground {
class Program {
static void Main() {
int a = 30;
for ( int i = 0; i < 10; i++ ) {
Console.Write( a + i ); // 編譯通過,在這裡可以使用外層的 a 及在此 for 陳述式內宣告的 i
Console.Write( " " );
}
for ( int i = 10; i >= 0; i-- ) { // 注意:這裡的 i 與上一個 for 迴圈的 i 不是同一份資料,只是同名
Console.Write( a + i ); // 編譯通過,在這裡可以使用外層的 a 及在此 for 陳述式內宣告的 i
Console.Write( " " );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment