[Script] The for Loop

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
Wesley
Regular Member
Posts: 137
Joined: Sun 12 Oct, 2008 1:42 am
Location: Boise, Idaho
Contact:

[Script] The for Loop

Post by Wesley »

Okay, I was looking at some scripting language and I could understand everything but this bit

Code: Select all

for i in xrange(j, 1, 1)

and

g = []
What does this mean? How would it look in C, C++, or Java?
ImageImage
ImageImage
Image
polarBody
New Member
Posts: 23
Joined: Wed 02 Sep, 2009 3:01 pm
Location: Chicago, IL

Re: [Script] The for Loop

Post by polarBody »

This is Python, right? Based on my limited experience with Python I could hazard a guess.

The xrange(j, 1, 1) statement effectively creates a range of numbers between j and 1, incrementing by 1. So for each iteration of the for statement, i gets assigned to the next value in this range, until i exceeds the range. Based on this description, you should be able to convert this to Java if you're familiar enough with Java for loops.

I'm 100% not sure about the second statement, but I think it creates an empty list called g, which you can later fill up with any kind of object (strings, numbers, other lists, etc.). There's no simple analogue to this statement in Java.
Post Reply