while loop
setup counter variable, condition, update counter variable
int index = 0; while(index < 4){ Log.v("NumbersActivity", "Index: " + index + " value: " + words[index]); index++; }
for loop
for(int index = 0; index < words.size(); index++){ log.v("NumbersActivity", "Index: " + index + "Value: " + words.get(index)); }
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 ArrayListwords = new 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); for (int index = 0; index < words.size(); index++) { TextView wordView = new TextView(this); wordView.setText(words.get(index)); rootView.addView(wordView); index++; } } }