Computer Science Canada

Index command help

Author:  dakotabiscan [ Wed May 27, 2015 2:41 pm ]
Post subject:  Index command help

What is it you are trying to achieve?
I am trying to search a sentence more than once using the index command.


What is the problem you are having?
It only searches once and stop right then, even if I put it in a loop.


Describe what you have tried to solve this problem
Like I said, I have put it in a loop and I attempted a for loop but that messed up the whole program so I decided to take it out.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


var sent, look, tmp : string
var l2 : int %length of index
var l, l3 : int
loop
    put "Enter a sentence"
    get sent : *
    put "Enter a word/letters to find in sentence"
    get look
    cls
    if index (sent, look) not= 0 then
        put "Found (", look, ") in search"
        l3 := length (sent)
        l2 := length (look)
        l := index (sent, look) + l2
        for i : 1 .. index (sent, look) - 1
            tmp := sent (i)
            put tmp ..
        end for
        colourback (yellow)
        put look ..
        colourback (white)
        for i : l .. l3
            tmp := sent (i)
            put tmp ..
        end for
    else
        put "Did not find word in sentence"
    end if
    put " "
end loop



Please specify what version of Turing you are using
4.1.2


: