// Example on how to use loops, arrays and dictionaries
// Simple while counter
counter = 1;
length = 9;
while (counter <= length) {
log("Counter " ~ counter);
counter = counter + 1;
}
// Iterating arrays
my_list = ["apple", "banana", "orange"];
my_list[1] = "pear";
log(len(my_list)~" fruits in array");
push(my_list, "avocado");
log(len(my_list)~" fruits in array");
// foreach loop
foreach (my_list as item) {
log(item);
}
log("Array join " ~ join(my_list, ", "));
// Iterating dictonaries
dict = {"fruit" : "apple", "veggie" : "pumpkin"};
dict["fruit"] = "orange";
log(dict["fruit"]); // orange
foreach (dict as key : value) {
log(key ~ ": " ~ value);
}
Labels
Sample
(14)
Intent
(5)
Media
(5)
Location
(4)
Funny
(3)
HTTP
(3)
Sleep as Android
(3)
WiFi
(3)
Alarm
(2)
Recording
(2)
Regexp
(2)
Array
(1)
Basic
(1)
Battery
(1)
Browser
(1)
Calculator
(1)
Contacts
(1)
Content Provider
(1)
Cron
(1)
Dialog
(1)
Dictionary
(1)
Export
(1)
Function
(1)
GUI
(1)
Game
(1)
Loop
(1)
Random
(1)
SD Card
(1)
Social
(1)
Temperature
(1)
Text to Speech
(1)
Weather
(1)
Search Scripts
2012-02-13
Loops, Arrays and Dictionaries
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment