Computer Language/유니티

while문& for문 별찍기 놀이

알 수 없는 사용자 2014. 4. 4. 14:05

1. 이중 while

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

while(true){

row += 1;

print (count[row]);

if(count[row] == 0){

break;

}

col = 0;

text = " ";

while(col<count[row]){

col +=1;

text = text + "*";

}

print (text);

}

}

}



2. 2중 for

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

for(row = 0; count[row]>0; row++){

//print(count[row]);

text = " ";

for(col = 0; col < count[row]; col++){

text = text + "*";

}

print (text);

}

}

}

3. while문 for문

using UnityEngine;

using System.Collections;


public class ExWhile4 : MonoBehaviour {

void Start(){

int[] count = new int[]{7, 2, 3, 4, 5, 4, 3, 4, 1, 0} ;

int row = -1;

int col = 0;

int sum = 0;

string text = " ";

while(true)

{

row++;

if(count[row]==0){

break;

}

col = 0;

text = " ";

//for

for(col =0; col < count[row]; col++){

text = text + "*";

}

print(text);

// }

}

}

}