11일차 과제 링크 👉 11일차 과제
for(시작점;종료점;증감값) {
// 반복할 코드
}
for(var i=1; i<=10; i++) {
// i를 기준으로 1~10까지 반복
print(i); // 1~10 출력
}
%
: 나머지 구하는 연산자List myFriends = ['홍길동', '김길동', '이길동', '박길동', '최길동'];
for (var i=0; i<myFriends.length; i++) {
print(myFriends[i]);
}
for (var friend in myFriends) {
print(friend);
}
→ List를 for문 안에 in 키워드와 함께 줄 경우, 변수에 하나씩 꺼내서 반복문 돌게함for (var friend in myFriends) {
print(friend);
}
for (var friend in myFriends) {
print(friend);
}
myFriends.map((e) {
return Text(e);
}).toList();
['홍길동', '김길동', '이길동', '박길동', '최길동']
[Text('홍길동'), Text('김길동'), Text('이길동'), Text('박길동'), Text('최길동')]
var categories = ['식품', '생활', '디지털', '뷰티', '패션', '자동차', '할인'];
ListView(
scrollDirection: Axis.horizontal,
children: categories.map((e) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Chip(label: Text(e)),
);
}).toList(),
),
myFriends.where((e) {
return e.length == 5; // 조건은 boolean
})
var mathScore = [96, 92, 94, 95, 73, 98, 78, 82, 96, 48];
Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('10개월간의 수학 점수'),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: mathScore.where((e) {
return e > 80;
}).map((e) {
return Container(
width: e*2,
height: 24,
margin: const EdgeInsets.only(bottom: 8),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.greenAccent,
Colors.white
]
)
),
);
}).toList(),
),
],
),
),
),
),
void main() {
return runApp(MyApp());
}
void main() => runApp(MyApp());
List myFriends = ['홍길동', '김길동', '이길동', '박길동', '최길동'];
ListView.builder(
itemCount: myFriends.length,
itemBuilder: (context, index) {
return Text(myFriends[index]);
}
),
ㅎㅎ..ㅎㅎ....ㅎㅎ...........ㅎㅎ..ㅎㅎ....