# \[SOLVED\] Stuck cloudrip commander

**URL:** <https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439>\
**Category:** Adventurer\
**Created:** [April 8, 2015, 6:17am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439 "2015-04-08T06:17:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![captain\_electro](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@captain\_electro](https://discourse.codecombat.com/u/captain_electro)\
**Post date:** [April 8, 2015, 6:17am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/1 "2015-04-08T06:17:46Z")

</div>

```
while self.gold > self.costOf("soldier"):
    self.summon("soldier")
    
# Add a while loop to command all the soldiers.
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
self.command(soldier, "move", {"x": 50, "y": 40})

# Go join your comrades!

```

help

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [April 8, 2015, 6:56am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/2 "2015-04-08T06:56:21Z")

</div>

```python
# Add a while loop to command all the soldiers.

```

see comment in the default code…

---

<div class="post-metadata">

**Author:** ![bmmtstb](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bmmtstb/32/12265_2.png) [@bmmtstb](https://discourse.codecombat.com/u/bmmtstb)\
**Post date:** [April 8, 2015, 10:55am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/3 "2015-04-08T10:55:51Z")

</div>

```
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]

```

will always be the same soldier on Position 1… maybe change soldierIndex

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [April 8, 2015, 10:26pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/4 "2015-04-08T22:26:41Z")

</div>

yes. Those four lines after “# Add a while…” don’t need to change, you just have to insert the “while …:” statement at the proper point (and indent the lines following).

---

<div class="post-metadata">

**Author:** ![captain\_electro](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@captain\_electro](https://discourse.codecombat.com/u/captain_electro)\
**Post date:** [April 13, 2015, 3:12am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/5 "2015-04-13T03:12:17Z")

</div>

![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/2403/ecabb5316d8fe7f3.png)

---

<div class="post-metadata">

**Author:** ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://discourse.codecombat.com/u/dean)\
**Post date:** [May 29, 2015, 4:29pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/6 "2015-05-29T16:29:58Z")

</div>

i did it without using the while loop cause i didnt understand it is that ok

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [May 29, 2015, 8:26pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/7 "2015-05-29T20:26:09Z")

</div>

Well . . . . . . . . . That is and isn’t OK.

It is OK that you found a solution. 😄  
It isn’t OK that you didn’t learn how to use a while loop. ☹

I don’t think this is the first while-loop level. If it isn’t then go back to the previous level and review…

If it is the first, then:

```python
# Add a while loop to command all the soldiers.
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
self.command(soldier, "move", {"x": 50, "y": 40})

```

As I mentioned in an earlier reply, you don’t “change” any of those lines, you just “Add” a while loop:

```python
# Add a while loop to command all the soldiers.
soldiers = self.findFriends()
soldierIndex = 0
# pseudo code comments:
#while someIndexCounterThing some comparison to the length of some arrayOfObjects
    soldier = soldiers[soldierIndex]
    #someIndexCounterThing '-=' or '+=' 1
    self.command(soldier, "move", {"x": 50, "y": 40})

```

- Replace the “pseudo code” while with a proper while for your language using:
- the provided “counter/index” (psst: soldierIndex)
- the proper comparion \< \<= == =\> \> (psst: the index is set to zero so it is less than…)
- the length of the proper array (psst: you are commanding soldiers so the array is…)
- you also have to make sure that you increments/decrements the counter/index (psst: starting at zero means you are probably going to increment)
- otherwise you have an infinite loop, that always does something with the “first” soldier…

When it comes to the comparison don’t forget that the length is the number of things in the array, but most (not all) computer languages count starting at zero not one, so the last item in the array is the “length-1” item (0,1,2,3 = 4 items).

---

<div class="post-metadata">

**Author:** ![Autri\_Basu](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Autri\_Basu](https://discourse.codecombat.com/u/Autri_Basu)\
**Post date:** [June 19, 2015, 9:47pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/10 "2015-06-19T21:47:56Z")

</div>

I am also stuck on this level and I have a question. What is supposed to replace `#while someIndexCounterThing some comparison to the length of some arrayOfObjects` ?

---

<div class="post-metadata">

**Author:** ![J\_F\_B\_M](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_f_b_m/32/2756_2.png) [@J\_F\_B\_M](https://discourse.codecombat.com/u/J_F_B_M)\
**Post date:** [June 19, 2015, 10:43pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/11 "2015-06-19T22:43:28Z")

</div>

someIndexCounterThing is usually called `index`  
some comparison is usually `<`, `>`, `==`, `<=` or `=>`  
length of some arrayOfObjects is usually `array.length` or `len(array)`, depending on your language.

Put together this gives this:

```python
#PYTHON
index = 0
while index < len(array):
    #do something with the array
    index++

```

```javascript
//JAVASCRIPT
var index = 0;
while( index < array.length){
    //do something with the array
    index++;
}

```

---

<div class="post-metadata">

**Author:** ![Autri\_Basu](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Autri\_Basu](https://discourse.codecombat.com/u/Autri_Basu)\
**Post date:** [June 19, 2015, 11:48pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/12 "2015-06-19T23:48:59Z")

</div>

I get it now thanks!

---

<div class="post-metadata">

**Author:** ![BlackChess](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@BlackChess](https://discourse.codecombat.com/u/BlackChess)\
**Post date:** [August 15, 2015, 11:49am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/13 "2015-08-15T11:49:31Z")

</div>

Pls, here is my code i am stuck ☹:

‘’’# Summon some soldiers, then direct them to your base.

# Each soldier costs 20 gold.

while self.gold \> self.costOf(“soldier”):  
self.summon(“soldier”)

soldiers = self.findFriends()  
soldierIndex = 0  
soldier = soldiers[soldierIndex]  
Solno = 0  
while Solno \< 5:# Add a while loop to command all the soldiers.  
self.command(soldier, “move”, {“x”: 47, “y”: 40})  
Solno += 1

# Go join your comrades!

‘’’

---

<div class="post-metadata">

**Author:** ![BlackChess](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@BlackChess](https://discourse.codecombat.com/u/BlackChess)\
**Post date:** [August 15, 2015, 11:52am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/14 "2015-08-15T11:52:22Z")

</div>

Thank you GeundericusTheMighty!

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [August 15, 2015, 1:46pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/15 "2015-08-15T13:46:56Z")

</div>

You have the right idea for code formatting, but the backtick is " ` ", not " ’ ". It’s the one under the tilde on the upper left corner.

---

<div class="post-metadata">

**Author:** ![BlackChess](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@BlackChess](https://discourse.codecombat.com/u/BlackChess)\
**Post date:** [August 16, 2015, 5:59am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/16 "2015-08-16T05:59:56Z")

</div>

```python
while self.gold > self.costOf("soldier"):
    self.summon("soldier")
    
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
Solno = 0
while Solno < 5:# Add a while loop to command all the soldiers.
    self.command(soldier, "move", {"x": 47, "y": 40})
    Solno += 1
# Go join your comrades!
self.moveXY(50, 40)

```

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [August 16, 2015, 11:24pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/17 "2015-08-16T23:24:51Z")

</div>

Your problem is that you don’t redefine `soldier`. It stays as `soldiers[soldierIndex]` for the entire program. You should move that inside the loop.

Also, `SolNo` is unnecessary. You can just update `soldierIndex`.

---

<div class="post-metadata">

**Author:** ![BlackChess](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@BlackChess](https://discourse.codecombat.com/u/BlackChess)\
**Post date:** [August 19, 2015, 8:54am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/18 "2015-08-19T08:54:08Z")

</div>

Thank you

So this is what it should be?:

```python

# Summon some soldiers, then direct them to your base.

# Each soldier costs 20 gold.
while self.gold > self.costOf("soldier"):
    self.summon("soldier")
    
soldiers = self.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
while soldierIndex soldier:# Add a while loop to command all the soldiers.
    self.command(soldier, "move", {"x": 47, "y": 40})
    soldierIndex += 1
# Go join your comrades!
self.moveXY(50, 40)

```

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [August 19, 2015, 1:50pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/19 "2015-08-19T13:50:15Z")

</div>

Please don’t post correct code. That would make things too easy for others. Check whether the code works first. 😉

In this case, though, you still have a problem: `while soldierIndex soldier:` doesn’t really mean anything. You had the right idea before, but with the wrong variable.

---

<div class="post-metadata">

**Author:** ![li\_dart](https://avatars.discourse-cdn.com/v4/letter/l/a8b319/32.png) [@li\_dart](https://discourse.codecombat.com/u/li_dart)\
**Post date:** [August 30, 2015, 9:05am UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/21 "2015-08-30T09:05:38Z")

</div>

no need already.  
Thanks. I solved it

---

<div class="post-metadata">

**Author:** ![Rasgan](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@Rasgan](https://discourse.codecombat.com/u/Rasgan)\
**Post date:** [September 13, 2015, 2:08pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/22 "2015-09-13T14:08:09Z")

</div>

Hey guys,  
First of all. Thank’s for this awesome game. I’m really enjoing it.

I have a question about line: `soldier = soldiers[soldierIndex]` . Why it has to be inside a loop? I took me about an hour to finish this task, because of it. Can someone explain it to me?

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [September 13, 2015, 4:10pm UTC](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439/23 "2015-09-13T16:10:46Z")

</div>

Here’s an example:

```python
friends = findFriends()
friendIndex = 0
friend = friends[friendIndex]
while friendIndex < len(friends):
    # Do stuff
    friendIndex += 1

```

friendIndex is forever defined as friends[0]. Therefore, you will never command the rest.

[Next page](https://discourse.codecombat.com/t/solved-stuck-cloudrip-commander/3439.md?page=2)
