📄 ch4_02.cs
字号:
using System;
class CH4_2
{
public static void Main()
{
// Illustrate a simple for loop that counts from 1 to 5
for ( int i=0; i<5; ++i )
System.Console.WriteLine( "I = {0}", i );
// Illustrate two loops to first find a letter in a string
// and then to print it out until a space is encountered.
// This shows you how to skip initialization in the second
// loop
int nPos = 0;
string s = "this is a test of the emergency broadcast system";
for ( nPos = 0; nPos < s.Length; ++nPos )
if ( s[nPos] == 'b' )
break;
for ( ; nPos < s.Length; ++nPos )
{
if ( s[nPos] == ' ' )
break;
System.Console.Write(s[nPos]);
}
System.Console.WriteLine("\n");
// Finally, illustrate how to use the for loop for something
// other than an integer and how to change the increment
int state = 0;
for ( double d = 0.0; d < 5.0; )
{
System.Console.WriteLine( "D = {0}", d );
switch ( state )
{
case 0:
d += 0.1;
break;
case 1:
d += 0.2;
break;
case 2:
d += 0.5;
break;
}
state ++;
if ( state > 2 )
state = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -