# Parse Student Code

Often you just want to make sure students successfully used a particular function/command/structure.  The simplest way I have found to do this is just parse the student's code file and make sure what you are looking for is there.

The following example looks for the `for` keyword and checks that the student has used a for loop at least 1 time.&#x20;

***Note:** You may want to add more logic to this code if you heavily rely on it.  I have it check if the for is on a line with a comment or in a puts statement but technically there are other ways for students to pass the code by putting a for somewhere.*

**Grading Test:**

```ruby
require 'rspec'
require 'stringio'

RSpec.describe "CodingRoomsUnitTests" do

    describe "Code requires at least 1 FOR loop" do
        it "checking that coding has >= 1 FOR loop" do
            count = 0
            File.open("/usercode/example.rb").each do |line|
                if (line.include?('for') and !(line.include?('#') or line.include?('puts')))
                    count += 1
                end
            end
            expect(count).to be >= 1
        end
    end

end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auto-grade.joemazzone.net/ruby-examples/parse-student-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
