SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10. ____
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
while文のループが終わった状態から説明を始めます
j = 3
変数
Hello while: 0
Hello while: 1
Hello while: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の初期化を行います
int型のカウンタ変数iを0で初期化します
j = 3
i = 0
変数
Hello while: 0
Hello while: 1
Hello while: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の条件判定を行います
i < 3 は 0 < 3 でtrueなのでループの処理に入ります
j = 3
i = 0
変数
Hello while: 0
Hello while: 1
Hello while: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
Hello for: 0と出力します
j = 3
i = 0
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の}に到達したので更新処理に進みます
j = 3
i = 0
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の更新処理を行います
iの値がインクリメントされ1になります
j = 3
i = 1
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の条件判定を行います
i < 3 は 1 < 3 でtrueなのでループの処理に入ります
j = 3
i = 1
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
Hello for: 1と出力します
j = 3
i = 1
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の}に到達したので更新処理に進みます
j = 3
i = 1
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の更新処理を行います
iの値がインクリメントされ2になります
j = 3
i = 2
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の条件判定を行います
i < 3 は 2 < 3 でtrueなのでループの処理に入ります
j = 3
i = 2
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
Hello for: 2と出力します
j = 3
i = 2
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
Hello for: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の}に到達したので更新処理に進みます
j = 3
i = 2
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
Hello for: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の更新処理を行います
iの値がインクリメントされ3になります
j = 3
i = 3
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
Hello for: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
for文の条件判定を行います
i < 3 は 3 < 3 でfalseなのでループの処理を抜けます
j = 3
i = 3
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
Hello for: 2
出力
01. #include <bits/stdc++.h>
02. using namespace std;
03.
04. int main() {
05. int j = 0;
06. while (j < 3) {
07. cout << "Hello while: " << j << endl;
08. j++;
09. }
10.
11. for (int i = 0; i < 3; i++) {
12. cout << "Hello for: " << i << endl;
13. }
14.
15. }
main関数の}に到達したのでプログラムを終了します
j = 3
変数
Hello while: 0
Hello while: 1
Hello while: 2
Hello for: 0
Hello for: 1
Hello for: 2
出力

Más contenido relacionado

La actualidad más candente

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
C++でHello worldを書いてみた
C++でHello worldを書いてみたC++でHello worldを書いてみた
C++でHello worldを書いてみたfirewood
 
みんな大好き! Hello, World
みんな大好き! Hello, Worldみんな大好き! Hello, World
みんな大好き! Hello, WorldNaohiro Aota
 
プロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswiftプロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswiftTomohiro Kumagai
 
新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・Rubyでやってみた新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・RubyでやってみたTomoaki Ueda
 
Goの文法の実例と解説
Goの文法の実例と解説Goの文法の実例と解説
Goの文法の実例と解説Ryuji Iwata
 
AVAの話 #mentaicojs
AVAの話 #mentaicojsAVAの話 #mentaicojs
AVAの話 #mentaicojsHiroyuki Anai
 
すごいConstたのしく使おう!
すごいConstたのしく使おう!すごいConstたのしく使おう!
すごいConstたのしく使おう!Akihiro Nishimura
 
String representation in py3k
String representation in py3kString representation in py3k
String representation in py3kAtsuo Ishimoto
 
Scalaの限定継続の応用と基本
Scalaの限定継続の応用と基本Scalaの限定継続の応用と基本
Scalaの限定継続の応用と基本Kota Mizushima
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチンyohhoy
 
イニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswiftイニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswiftTomohiro Kumagai
 
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来Tomohiro Kumagai
 
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswiftSwift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswiftTomohiro Kumagai
 

La actualidad más candente (18)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
C++でHello worldを書いてみた
C++でHello worldを書いてみたC++でHello worldを書いてみた
C++でHello worldを書いてみた
 
みんな大好き! Hello, World
みんな大好き! Hello, Worldみんな大好き! Hello, World
みんな大好き! Hello, World
 
初めてのSTL
初めてのSTL初めてのSTL
初めてのSTL
 
プロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswiftプロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswift
 
新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・Rubyでやってみた新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・Rubyでやってみた
 
Goの文法の実例と解説
Goの文法の実例と解説Goの文法の実例と解説
Goの文法の実例と解説
 
AVAの話 #mentaicojs
AVAの話 #mentaicojsAVAの話 #mentaicojs
AVAの話 #mentaicojs
 
業務報告会
業務報告会業務報告会
業務報告会
 
Mock and patch
Mock and patchMock and patch
Mock and patch
 
すごいConstたのしく使おう!
すごいConstたのしく使おう!すごいConstたのしく使おう!
すごいConstたのしく使おう!
 
String representation in py3k
String representation in py3kString representation in py3k
String representation in py3k
 
Scalaの限定継続の応用と基本
Scalaの限定継続の応用と基本Scalaの限定継続の応用と基本
Scalaの限定継続の応用と基本
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン
 
イニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswiftイニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswift
 
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
 
関数
関数関数
関数
 
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswiftSwift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
 

for文

  • 1. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. ____ 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } while文のループが終わった状態から説明を始めます j = 3 変数 Hello while: 0 Hello while: 1 Hello while: 2 出力
  • 2. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の初期化を行います int型のカウンタ変数iを0で初期化します j = 3 i = 0 変数 Hello while: 0 Hello while: 1 Hello while: 2 出力
  • 3. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の条件判定を行います i < 3 は 0 < 3 でtrueなのでループの処理に入ります j = 3 i = 0 変数 Hello while: 0 Hello while: 1 Hello while: 2 出力
  • 4. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } Hello for: 0と出力します j = 3 i = 0 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 出力
  • 5. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の}に到達したので更新処理に進みます j = 3 i = 0 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 出力
  • 6. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の更新処理を行います iの値がインクリメントされ1になります j = 3 i = 1 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 出力
  • 7. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の条件判定を行います i < 3 は 1 < 3 でtrueなのでループの処理に入ります j = 3 i = 1 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 出力
  • 8. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } Hello for: 1と出力します j = 3 i = 1 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 出力
  • 9. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の}に到達したので更新処理に進みます j = 3 i = 1 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 出力
  • 10. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の更新処理を行います iの値がインクリメントされ2になります j = 3 i = 2 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 出力
  • 11. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の条件判定を行います i < 3 は 2 < 3 でtrueなのでループの処理に入ります j = 3 i = 2 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 出力
  • 12. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } Hello for: 2と出力します j = 3 i = 2 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 Hello for: 2 出力
  • 13. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の}に到達したので更新処理に進みます j = 3 i = 2 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 Hello for: 2 出力
  • 14. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の更新処理を行います iの値がインクリメントされ3になります j = 3 i = 3 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 Hello for: 2 出力
  • 15. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } for文の条件判定を行います i < 3 は 3 < 3 でfalseなのでループの処理を抜けます j = 3 i = 3 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 Hello for: 2 出力
  • 16. 01. #include <bits/stdc++.h> 02. using namespace std; 03. 04. int main() { 05. int j = 0; 06. while (j < 3) { 07. cout << "Hello while: " << j << endl; 08. j++; 09. } 10. 11. for (int i = 0; i < 3; i++) { 12. cout << "Hello for: " << i << endl; 13. } 14. 15. } main関数の}に到達したのでプログラムを終了します j = 3 変数 Hello while: 0 Hello while: 1 Hello while: 2 Hello for: 0 Hello for: 1 Hello for: 2 出力