标签:com lap with 简写 控制流 wro 错误提示 执行 for循环
//标准语句
bool isWrong = true;
bool isTesting = false;
if (isWrong) {
print(‘错误提示‘);
} else if (isTesting) {
print(‘正在测试‘);
} else {
print(‘其他‘);
}
//简写
bool isWrong = true;
if (isWrong) print(‘错误‘);
//for loop
List list = [1, 2, 3, 4, 5];
for (int i = 0; i < list.length; i++) {
print(list[i]);
}
//forEach
List list = [1, 2, 3, 4, 5];
list.forEach((element) {
print(element);
});
//for-in
List list = [1, 2, 3, 4, 5];
for (var i in list) {
print(i);
}
//while
List list = [1, 2, 3, 4, 5];
int i = 0;
while (i < list.length) {
print(list[i]);
i++;
}
//do-while
List list = [1, 2, 3, 4, 5];
int i = 0;
do {
print(list[i]);
i++;
} while (i < list.length);
switch (1) {
case 1:
print(‘books‘);
break;
case 2:
print(‘pen‘);
break;
case 3:
print(‘laptop‘);
break;
case 4:
print(‘phone‘);
break;
default:
print(‘other‘);
}
String urlString = ‘http://www.baidu.com‘;
assert(urlString.startsWith(‘https‘),
‘URL ($urlString) should start with "https".‘);
// 当urlString不是以https开头时,代码的执行会被打断
// 当urlString是以https开头时,代码会继续执行
标签:com lap with 简写 控制流 wro 错误提示 执行 for循环
原文地址:https://www.cnblogs.com/TobuTobu/p/14398752.html