while (condition) {
Instruction
Update counter variable
}
int count = 0;
while(count < 3){
playSound();
count = count + 1;
}
[java]
int index = 0;
while(index < 4){
Log.v("NumbersActivity",
"Index: " + index + "
value: " + words[index]);
index++;
}
[/java]
NumbersActivity.java
[java]
import androis.os.Bundle;
import android.support.v7.app.AppCompactActivity;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
package com.example.android.miwok;
public class NumbersActivity extends AppCompactActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_numbers);
// Create on array of words
ArrayList
words.add(“one”);
words.add(“two”);
words.add(“three”);
words.add(“four”);
words.add(“five”);
words.add(“six”);
words.add(“seven”);
words.add(“eight”);
words.add(“nine”);
words.add(“ten”);
LinearLayout rootView = (LinearLayout)findViewById(R.id.rootView);
int index = 0;
while (index < words.size()){
TextView wordView = new TextView(this);
wordView.setText(words.get(index));
rootView.addView(wordView);
index++;
}
}
}[/java]
for (Setup counter variable; Condition; Update counter variable){
Instructions
}